import Vue from 'vue'
import App from './App.vue'
import router from './router/index.js'
import store from './store/index.js'
import {getToken} from './libs/util.js'




Vue.config.productionTip = false
import 'assets/css/bootstrap.min.css'
import 'assets/css/font-awesome.min.css'
import 'assets/css/animate.css'
import 'assets/css/swiper.css'
import 'assets/css/owl.carousel.min.css'
import 'assets/css/style.css'
import 'assets/css/responsive.css'
import 'assets/css/magnific-popup.css'




new Vue({
  render: h => h(App),
  router,
  store
}).$mount('#app')

// import config from './config'
// import {
//   check_token
// } from './api/user.js'

// 导入element
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
//使用element
Vue.use(ElementUI, { size: 'small', zIndex: 3000 });

const whiteRouter = ['/login'];

router.beforeEach((to, from, next) => {
  // 检查待跳转的路由的meta中的loginReqired属性值 => true => 需要检查权限
  if(getToken()) {
    // console.log("需要登录")
    next()
    }else{
      if(whiteRouter.indexOf(to.path) !== -1){
        next();
      }else{
        next('/login') // 路由指向
      }
    }
    // next()
    // check_token(store.state.user.token).then(
    //   res => {
    //     console.log(res.data)
    //     if (res.data === "ok") {
    //       // token验证成功
    //       next()
    //     } else {
    //       // token验证失败
    //       next({
    //         // path: '/login/',
    //         name: config.loginName,
    //         query: {
    //           redirect: to.fullPath
    //         }
    //       })
    //     }
    //   })

})
